home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Utilities / Programming / EnterAct 3.5 / Drag_on Modules / hAWK programs / $XRef < prev    next >
Encoding:
Text File  |  1993-04-09  |  4.3 KB  |  146 lines  |  [TEXT/KEEN]

  1. # $XRef: from one or more source files, build a cross-reference list
  2. #of all top-level terms. The built-in function "lookup" must be
  3. #supported by the application calling hAWK (at present this means just
  4. #EnterAct).  For this to work properly when called from EnterAct, you
  5. #must have a project open, the project must include files which define
  6. #all the terms you wish to cross-reference (include the toolbox headers
  7. #in your project if you want toolbox terms cross-referenced), and your
  8. #dictionary should be up to date.
  9. #Similar to $XRef_Full, but DOES skip over comments and strings.
  10. #Use "Set variables" when calling this program to specify which kinds
  11. #of terms to include in the cross-reference. There are eight kinds of
  12. #terms, and eight corresponding variables that can be set to 0 or 1,
  13. #eg do_defines=0 means don't include defines, whereas do_defines=1 means
  14. #include defines.
  15. #
  16. #Typically use the “MFS selected files” input option on one or more files.
  17. #Any other input option is also OK, just ensure an appropriate EnterAct
  18. #project is open before running this program.
  19. #
  20. #The array "skipList" (see "XRef.T") holds a list of common terms to skip over.
  21. #In large cross-reference jobs it may be NECESSARY to skip the commonest
  22. #terms to avoid overflowing the list of references. 
  23.  
  24. # User’s Manual references:
  25. # «hAWK User’s Manual» «F   Running hAWK programs»
  26. # «hAWK User’s Manual» «L  5   Regular expressions»
  27. # «hAWK User’s Manual» «M  5   Built-in string and file functions»
  28. # «hAWK User’s Manual» «K  4   Built-in variables»
  29. # «hAWK User’s Manual» «K  8   Arrays»
  30. # «hAWK User’s Manual» «N   User-defined functions»
  31. # «hAWK User’s Manual» «P  3   The getline function»
  32. # «hAWK User’s Manual» «O  3   Output into files»
  33. # «hAWK User’s Manual» «Q   The hAWK function»
  34.  
  35. BEGIN {
  36.     if (do_defines == 0 && do_variables == 0 && do_functions == 0 &&
  37.         do_enumConsts == 0 && do_typedefs == 0 && do_structs == 0 &&
  38.         do_unions == 0 && do_enums == 0)
  39.         {
  40.         print "Please use the Set variables button"
  41.         print "and select which kinds of term to reference."
  42.         print "Currently all the selector variables are zero."
  43.         exit
  44.         }
  45.     #Generate the actual xref program from the template program
  46.     #First, a couple of arrays to simplify things
  47.     if (do_defines != 0)
  48.         {
  49.         numfor["defines"] = 1
  50.         namefor["defines"] = ": #define"
  51.         }
  52.     if (do_variables != 0)
  53.         {
  54.         numfor["vars"] = 2
  55.         namefor["vars"] = ": variable"
  56.         }
  57.     if (do_functions != 0)
  58.         {
  59.         numfor["funcs"] = 4
  60.         namefor["funcs"] = ": function"
  61.         }
  62.     if (do_enumConsts != 0)
  63.         {
  64.         numfor["enumCs"] = 8
  65.         namefor["enumCs"] = ": enum constant"
  66.         }
  67.     if (do_typedefs != 0)
  68.         {
  69.         numfor["typedefs"] = 16
  70.         namefor["typedefs"] = ": typedef"
  71.         }
  72.     if (do_structs != 0)
  73.         {
  74.         numfor["structs"] = 32
  75.         namefor["structs"] = ": struct tag"
  76.         }
  77.     if (do_unions != 0)
  78.         {
  79.         numfor["unions"] = 64
  80.         namefor["unions"] = ": union tag"
  81.         }
  82.     if (do_enums != 0)
  83.         {
  84.         numfor["enums"] = 128
  85.         namefor["enums"] = ": enum tag"
  86.         }
  87.     templateFile = STDPATH "Drag_on Modules:hAWK programs:" "XRef.T"
  88.     actualFile = STDPATH "Drag_on Modules:hAWK programs:" "XRef.A"
  89.     while (getline < templateFile > 0)
  90.         {
  91.         if (match($0, /##MARK record/))
  92.             {
  93.             ++tLines
  94.             for (i in numfor) #exercise: sort this by numeric value?
  95.                 {
  96.                 if (doneIf)
  97.                     print "\t\telse if (type == " numfor[i] ") #" namefor[i] > actualFile
  98.                 else #First one, omit the else
  99.                     print "\t\tif (type == " numfor[i] ") #" namefor[i] > actualFile
  100.                 #print defines[$i] = defines[$i] "\t" fIndex "\t" FNR
  101.                 print "\t\t\t" i "[$i] = " i "[$i] \"\\t\" fIndex \"\\t\" FNR" > actualFile
  102.                 doneIf = 1
  103.                 }
  104.             }
  105.         else if (match($0, /##MARK linear/))
  106.             {
  107.             ++tLines
  108.             for (i in numfor)
  109.                 {
  110.                 print "\tfor (w in " i ")" > actualFile
  111.                 print "\t\t{" > actualFile
  112.                 print "\t\tlinear[++m] = w \"" namefor[i] "\" " i "[w]" > actualFile
  113.                 print "\t\tdelete " i "[w]" > actualFile
  114.                 print "\t\t}" > actualFile
  115.                 }
  116.             }
  117.         else
  118.             print > actualFile
  119.         }
  120.     if (tLines < 2)#template missing or damaged
  121.         {
  122.         print "The template file"
  123.         print templateFile
  124.         if (!tLines)
  125.             print "is damaged or missing."
  126.         else
  127.             print "is damaged."
  128.         exit
  129.         }
  130.     else
  131.         {
  132.         close(templateFile)
  133.         close(actualFile)
  134.         }
  135.     ##TEST
  136.     ##exit
  137.     #Execute the new specific program XRef.A
  138.     argv[x++] = "hAWK"
  139.     argv[x++] = "-f" actualFile
  140.     argv[x++] = "--"
  141.     for (i = 1; i < ARGC; ++i)
  142.         argv[x++] = ARGV[i]
  143.     hAWK(argv)
  144.     }
  145.  
  146.